package org.jtb.quickr;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.log4j.Logger;

class QuickrProperties {
    private static Logger logger = Logger.getLogger(QuickrProperties.class.getName());    
    private static QuickrProperties quickrProperties = null;
    
    private Properties properties;
    
    private QuickrProperties() throws QuickrException {
        InputStream is = this.getClass().getResourceAsStream("/quickr.properties");
        if (is == null) {
            throw new QuickrException("could not find quickr.properties in class path");            
        }
        
        properties = new Properties();
        
        try {
            properties.load(is);
        } catch (IOException ioe) {
            throw new QuickrException("could not load quickr.properties", ioe);
        }
        if (logger.isDebugEnabled()) {
            logger.debug("quickr.properties:\n" + properties);
        }
    }
    
    public static synchronized QuickrProperties getDefaultInstance() throws QuickrException {
        if (quickrProperties == null) {
            quickrProperties = new QuickrProperties();
        }
        return quickrProperties;
    }

    public QuickrProperties(Properties properties) {
        this.properties = properties;
    }
    
    public String getRestUrl() {
        return properties.getProperty("restUrl").trim();
    }
    
    public String getApiKey() {
        return properties.getProperty("apiKey").trim();
    }
    
    public String getSecret() {
        return properties.getProperty("secret").trim();
    }
    
    public String getAuthUrl() {
        return properties.getProperty("authUrl").trim();
    }
    
    public String getStaticUrl() {
        return properties.getProperty("staticUrl").trim();
    }

    public String getUploadUrl() {
        return properties.getProperty("uploadUrl").trim();
    }
}
